package com.titar.robot.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.RelativeLayout;

import com.titar.robot.R;


/**
 * 根据布局展示dialog
 */

public class DialogOnLayout {
    private Dialog dialogVoice;
    private RelativeLayout layout;
    private Display display;

    //获取dialog对象
    public static Dialog getLayoutDialog(Context context, int layoutRes){
        DialogOnLayout layout=new DialogOnLayout();
        return layout.getAllDialog(context,layoutRes);
    }

    public Dialog getAllDialog(Context context, int layoutRes) {
        WindowManager windowManager = (WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE);
        display = windowManager.getDefaultDisplay();
        layout = (RelativeLayout) View.inflate(context, layoutRes, null);
        layout.setMinimumWidth(display.getWidth());

        dialogVoice = new Dialog(context, R.style.ActionSheetDialogStyle2);
        dialogVoice.setContentView(layout);
        dialogVoice.setCanceledOnTouchOutside(true);
        dialogVoice.setCancelable(true);
        Window dialogWindow = dialogVoice.getWindow();
        dialogWindow.getDecorView().setPadding(0, 0, 0, 0);
        dialogWindow.setGravity(Gravity.CENTER);
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
      //  lp.width = (int) (display.getWidth());
        lp.width= RelativeLayout.LayoutParams.WRAP_CONTENT;
        lp.height= RelativeLayout.LayoutParams.WRAP_CONTENT;
        dialogWindow.setAttributes(lp);
        return dialogVoice;
    }

}
